package com.slipper.qmt.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Monitor extends Thread {
    private static final Logger logger = LoggerFactory.getLogger(Monitor.class);

    private boolean shutdown = false;
    private final TaskList taskList;

    public Monitor(TaskList taskList) {
        this.taskList = taskList;
    }

    public void run() {
        while (!shutdown) {
            showInfo();
        }
    }

    public void showInfo() {
        try {
            logger.info("总处理任务数：{}, 当前剩余任务数：{}",
                    this.taskList.getTotalSize(),
                    this.taskList.getCurrSize());
            Thread.sleep(5 * 60 * 1000);
        } catch (InterruptedException e) {
            logger.info("监听出错。", e);
        }
    }

    public void shutdown() {
        this.shutdown = true;
    }
}
